package com.neu.cpsp.controller;

import com.neu.cpsp.pojo.RegulationDetail;
import com.neu.cpsp.pojo.RegulationDetailAndTimes;
import com.neu.cpsp.service.RegulationDetailAndTimesService;
import com.neu.cpsp.util.result.Result;
import com.neu.cpsp.util.result.ResultGenerator;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
    @create 2022/4/15
*/

@CrossOrigin
@RestController
@RequestMapping("/regulationdetailtimes")
public class RegulationDetailAndTimesController {

    @Autowired
    RegulationDetailAndTimesService regulationDetailAndTimesService;

    @ApiOperation("添加记录（Regulation_detail与Regulation_times表同时修改）")
    @PostMapping(value = "/addDetailAndTimes")
    @ResponseBody
    public Result addForm(@RequestBody RegulationDetailAndTimes regulationDetailAndTimes) throws Exception {
        return ResultGenerator.genSuccessResult(regulationDetailAndTimesService.submitForm(regulationDetailAndTimes));
    }

    @ApiOperation("修改记录（Regulation_detail与Regulation_times表同时修改）,id为必选参数")
    @PostMapping(value = "/updateDetailAndTimes")
    @ResponseBody
    public Result update(@RequestBody RegulationDetailAndTimes regulationDetailAndTimes) throws Exception {
        return ResultGenerator.genSuccessResult(regulationDetailAndTimesService.update(regulationDetailAndTimes));
    }

    @ApiOperation("删除记录,id为detail表的id，同时删除Regulation_detail与Regulation_times表里的记录")
    @PostMapping(value = "/deleteDetailAndTimes")
    @ResponseBody
    public Result delete(@RequestParam Integer id) throws Exception {
        return ResultGenerator.genSuccessResult(regulationDetailAndTimesService.delete(id));
    }

    @ApiOperation("联合Regulation_detail以及Regulation_times表查询")
    @PostMapping(value = "/selectDetailAndTimes")
    @ResponseBody
    public Result selectDetailAndTimes(RegulationDetail regulationDetail){
        return ResultGenerator.genSuccessResult(regulationDetailAndTimesService.getTypeAndDetail(regulationDetail));
    }
}
